package ru.stepanovdn.trading.server.entity

import io.hypersistence.utils.hibernate.type.json.JsonType
import jakarta.persistence.*
import org.hibernate.annotations.Type
import java.time.OffsetDateTime
import java.math.BigDecimal
import java.time.LocalDateTime
import org.hibernate.annotations.CreationTimestamp


@Entity
@Table(
    name = "offer",
    indexes = [Index(columnList = "figi"), Index(columnList = "strategy"), Index(columnList = "currency")]
)
data class Order (
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long? = null,

    @Column(name = "figi", nullable = false)
    var figi: String? = null,

    @Column(name = "figi_title", nullable = true)
    var figiTitle: String? = null,

    @Column(name = "purchase_price", nullable = false, scale = 8, precision = 19)
    var purchasePrice: BigDecimal? = null,

    @Column(name = "purchase_commission", nullable = false, scale = 8, precision = 19)
    var purchaseCommission: BigDecimal? = null,

    @Column(name = "purchase_date_time", nullable = false)
    var purchaseDateTime: OffsetDateTime? = null,

    @Column(name = "sell_price", nullable = true, scale = 8, precision = 19)
    var sellPrice: BigDecimal? = null,

    @Column(name = "sell_date_time", nullable = true)
    var sellDateTime: OffsetDateTime? = null,

    @Column(name = "sell_profit", nullable = true, scale = 8, precision = 19)
    var sellProfit: BigDecimal? = null,

    @Column(name = "sell_commission", nullable = true, scale = 8, precision = 19)
    var sellCommission: BigDecimal? = null,

    @Column(name = "strategy", nullable = false)
    var strategy: String? = null,

    @Column(name = "currency", nullable = false)
    var currency: String? = null,

    val lots: Int? = null,

    @Type(JsonType::class)
    @Column(name = "details", columnDefinition = "jsonb")
    var details: OrderDetails? = null,

    @Version
    @Column(name = "version", nullable = false)
    var version: Int? = null,

    @CreationTimestamp
    @Column(name = "created", nullable = false)
    var created: LocalDateTime? = null
)
